package com.coolwar.design.proxy.dynamic.mybatis;

import com.coolwar.design.proxy.dynamic.mybatis.dao.IGradeDao;
import com.coolwar.design.proxy.dynamic.mybatis.dao.IStudentDao;
import com.coolwar.design.proxy.dynamic.mybatis.model.Grade;
import com.coolwar.design.proxy.dynamic.mybatis.model.Student;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Coolwar
 * <p>
 * 模拟mybatis无实现类执行
 */
public class Test {

    public static void main(String[] args) {
        DefaultSqlSession defaultSqlSession = new DefaultSqlSession();

        IStudentDao studentDao = new ProxyFactory<>(defaultSqlSession, IStudentDao.class).newInstance();
        Student student = new Student();
        student.setAge(18);
        student.setName("wendong");
        int save = studentDao.save(student);
        System.out.println("执行影响行数：" + save);

        Student s1 = studentDao.select("id1");
        System.out.println("查询返回：" + s1);

        Map<String, Object> param = new HashMap<>(2);
        param.put("name", "张三");
        List<Student> search = studentDao.search(param);
        System.out.println("查询返回：" + search);

        System.out.println("");

        IGradeDao iGradeDao = new ProxyFactory<>(defaultSqlSession, IGradeDao.class).newInstance();
        Grade grade = new Grade();
        grade.setId("2");
        grade.setNumber(12);
        int i = iGradeDao.save(grade);
        System.out.println("执行影响行数：" + i);

        Grade s2 = iGradeDao.select("id1");
        System.out.println("查询返回：" + s2);

        Map<String, Object> param1 = new HashMap<>(2);
        param1.put("name", "张三");
        List<Grade> search1 = iGradeDao.search(param);
        System.out.println("查询返回：" + search1);
    }

}
